package com.kx.springmybatis.service.impl;

import com.kx.springmybatis.mapper.UserMapper;
import com.kx.springmybatis.pojo.User;
import com.kx.springmybatis.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

/**
 * @ClassName UserServiceIMpl
 * @Author Sun
 * @Date 2021/5/18 22:19
 */
@Service
@Transactional  //全部是默认设置
public class UserServiceImpl implements UserService {

    @Autowired
    private UserMapper userMapper;

    @Override
    @Transactional(readOnly = true, propagation = Propagation.SUPPORTS)
    public User getUserById(long id) {
        User user = userMapper.getUserById(id);
        return user;
    }

    @Override
    public void addUser(User user) {
        userMapper.addUser(user);
    }

    @Override
    public int updateUser(User user) {
        return userMapper.updateUser(user);
    }

    @Override
    public int deleteUserById(long id) {
        return userMapper.deleteUserById(id);
    }

}
